﻿/*
 * Rappelz: Endless Odyssey - The first free open source Rappelz server emulator
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rappelz.GameServer.Network;
using System.Data.Common;
using System.Data;
using Rappelz.GameServer.Network.GameClient;

namespace Rappelz.GameServer.Database
{
    /// <summary>
    /// DB_InsertFavor (smp_read_character_list, smp_read_item_equip_info)
    /// </summary>
    public class DB_UpdateQuest : IDBProc
    {
        private Player m_pPlayer;
        private int m_nOwnerID;
        private int m_nID;
        private int m_nStatus1;
        private int m_nStatus2;
        private int m_nStatus3;
        private int m_nStatus4;
        private int m_nStatus5;
        private int m_nStatus6;
        private int m_nProgress;
        private uint m_nTime;
        public BaseObject m_CBObject = null;

        private enum DBFields : int
        {
            AccountId = 0,
        }

        public DB_UpdateQuest(Player player, int owner_id, int id, int status1, int status2, int status3, int status4, int status5, int status6, int progress, uint time_remaining)
        {
            m_pPlayer = player;
            m_nOwnerID = owner_id;
            m_nID = id;
            m_nStatus1 = status1;
            m_nStatus2 = status2;
            m_nStatus3 = status3;
            m_nStatus4 = status4;
            m_nStatus5 = status5;
            m_nStatus6 = status6;
            m_nProgress = progress;
            m_nTime = time_remaining;
        }

        public void SetCB(BaseObject obj)
        {
            m_CBObject = obj;
        }

        public void RunCB()
        {
            if (m_CBObject != null)
                m_CBObject.onEndQuery();
        }

        public bool onProcess()
        {
            DbConnection conn = GameDBManager.Instance.CreateConnection();
            DbCommand cmd = conn.CreateCommand();

            cmd.CommandText = "smp_update_quest";
            cmd.CommandType = CommandType.StoredProcedure;

            DbParameter IN_OWNER_ID = GameDBManager.Instance.CreateInParameter(cmd, "IN_OWNER_ID", DbType.Int32, this.m_nOwnerID);
            DbParameter IN_ID = GameDBManager.Instance.CreateInParameter(cmd, "IN_ID", DbType.String, this.m_nID);
            DbParameter IN_TIME = GameDBManager.Instance.CreateInParameter(cmd, "IN_TIME", DbType.Int32, this.m_nTime);
            DbParameter IN_STATUS1 = GameDBManager.Instance.CreateInParameter(cmd, "IN_STATUS1", DbType.Int32, this.m_nStatus1);
            DbParameter IN_STATUS2 = GameDBManager.Instance.CreateInParameter(cmd, "IN_STATUS2", DbType.Int32, this.m_nStatus2);
            DbParameter IN_STATUS3 = GameDBManager.Instance.CreateInParameter(cmd, "IN_STATUS3", DbType.Int32, this.m_nStatus3);
            DbParameter IN_STATUS4 = GameDBManager.Instance.CreateInParameter(cmd, "IN_STATUS4", DbType.Int32, this.m_nStatus4);
            DbParameter IN_STATUS5 = GameDBManager.Instance.CreateInParameter(cmd, "IN_STATUS5", DbType.Int32, this.m_nStatus5);
            DbParameter IN_STATUS6 = GameDBManager.Instance.CreateInParameter(cmd, "IN_STATUS6", DbType.Int32, this.m_nStatus6);
            DbParameter IN_PROGRESS = GameDBManager.Instance.CreateInParameter(cmd, "IN_PROGRESS", DbType.Int32, this.m_nProgress);

            conn.Open();
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Globals.Log.Error("DB_UpdateQuest.onProcess Exception: {0}", ex);
            }
            conn.Close();
            return true;
        }
    }



}
